<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

    <script>
        $(function () {
            var oldcon = console.log
            window.console.log = function (res) {
                oldcon(res)
                document.body.innerHTML += res + '</br>'
            }
        })

        $(function () {
            var gooleMap = {
                show() {
                    console.log('开始渲染谷歌地图')
                }
            }
            var baiduMap = {
                show() {
                    console.log('开始渲染百度地图')
                }
            }
            var sosoMap = {
                show() {
                    console.log('开始渲染soso地图')
                }
            }


            var renderMap = function (type) {
                if (type == 'google')
                    gooleMap.show()
                else if (type == 'baiduMap')
                    baiduMap.show()
            }


            renderMap('google')
            renderMap('baiduMap')

            // 上述的弹性太脆弱，优化

            renderMap = function (map) {
                if (map.show instanceof Function) {
                    map.show()
                }
            }

            renderMap(sosoMap)

        })
    </script>
</head>

<body>
</body>

</html>